<?php
	require_once("include/jara_fns.php");
	try {
		jara_page_start("Author profile");
		@$username = $_REQUEST["username"];
		if(!get_magic_quotes_gpc()) {
			$username = addslashes($username);
		}
		$query = "select * from jara_posts where author = '$username'";
		$result = jara_db_query($query);
		if($result->num_rows == 0) {
			throw new JaraGeneralException("The requested user has not written any posts.");
		}
		$num_rows = $result->num_rows;
		echo "<p><strong>$username</strong> has written <strong>$num_rows</strong> posts.</p>";
		for($i = 0; $i < $num_rows; $i++) {
			$row = $result->fetch_assoc();
			echo "<p>";
			echo "<a href=\"".jara_permalink($row["id"], "url")."\"><strong>".$row["title"]."</strong></a> - written at ".date("jS M Y", $row["time"])."<br />";
			echo nl2br(substr(strip_tags($row["text"]), 0, 200)) . " [...]";
			echo "</p>";
		}
		jara_page_end();
	}
	catch(JaraDatabaseException $ex) {
?>
<p>
	A database error occured during the process of creating this page.
</p>
<p>
	Error type: <?php echo (($ex->getSqlStage() == 1) ? "MySQL connection error" : "MySQL query error"); ?><br />
	Error message: &quot;<?php echo $ex->getSqlMsg(); ?>&quot; [code <?php echo $ex->getSqlCode(); ?>]
</p>
<?php
		jara_page_end();
		exit;
	}
	catch(JaraGeneralException $ex) {
?>
<p>
	A general error occured during the process of creating this page.
</p>
<p>
	Error message: &quot;<?php echo $ex->getMessage(); ?>&quot;
</p>
<?php
		jara_page_end();
		exit;
	}
?>